package com.lza.handle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lza.phone.entity.User;
import com.lza.phone.service.CapacityService;
import com.lza.phone.service.PhoneService;
import com.lza.phone.service.UserService;
import com.lza.security.JwtAuthenticationTokenFilter;
import com.lza.security.JwtTokenUtil;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 根据token生成用户
 */
@Component
public class FromTokenGetUser {
    @Autowired
    CapacityService capacityService;
    @Autowired
    UserService userService;
    @Autowired
    JwtTokenUtil jwtTokenUtil;
    @Autowired
    JwtAuthenticationTokenFilter jwtAuthenticationTokenFilter;
    public User getUser(){
        String name = jwtTokenUtil.getUserNameFromToken(jwtAuthenticationTokenFilter.getToken());
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("username",name);
        User user = userService.getOne(queryWrapper);
        return user;
    }
}
